package com.neuedu.javase.api;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-09-29 9:39
 * 描述 :
 */
public class MyCalendar {
    public static void main(String[] args) {
        //对象的创建
        Calendar calendar =  Calendar.getInstance();
        System.out.println("calendar.getClass() = " + calendar.getClass());


        System.out.println("calendar = " + calendar);

        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        int hour = calendar.get(Calendar.HOUR);
        int min = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);

        System.out.println("year = " + year);
        System.out.println("month = " + month); // 月份  0
        System.out.println("dayOfMonth = " + dayOfMonth);
        System.out.println("hour = " + hour);
        System.out.println("min = " + min);
        System.out.println("second = " + second);


        Date time = calendar.getTime();//瞬时时间

        System.out.println("new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\").format(time) = " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time));


        //有效的时区 ID
        String[] availableIDs = TimeZone.getAvailableIDs();
        for (String availableID : availableIDs) {
            System.out.println("availableID = " + availableID);
        }

//        Calendar calendar1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Berlin"));
        Calendar calendar1 = Calendar.getInstance(TimeZone.getTimeZone("Etc/GMT+6") ,new Locale("en","us"));
        System.out.println("new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\").format(time) = " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar1.getTime()));


//        calendar1.compareTo()
//        calendar1.before()
//        calendar1.set(year,month,date);


        calendar1.set(Calendar.YEAR ,2012);

//        calendar1.add();

        Calendar calendar2 = Calendar.getInstance();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("sdf.format( calendar2.getTime()) = " + sdf.format(calendar2.getTime()));
        calendar2.add(Calendar.YEAR,2);
        System.out.println("sdf.format( calendar2.getTime()) = " + sdf.format(calendar2.getTime()));
        calendar2.add(Calendar.DAY_OF_MONTH,3);
        System.out.println("sdf.format( calendar2.getTime()) = " + sdf.format(calendar2.getTime()));

    }
}
